package com.zyzd.baseretrofit.activity;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zyzd.baseretrofit.R;
import com.zyzd.baseretrofit.base.activity.BaseRecyclerViewActivity;
import com.zyzd.baseretrofit.base.adapter.BaseRecyclerAdapter;
import com.zyzd.baseretrofit.bean.remote.ApiResultBean;
import com.zyzd.baseretrofit.bean.remote.PerformanceListBean;

import java.util.ArrayList;

import rx.Observable;

public class PerformerActivity extends BaseRecyclerViewActivity<PerformanceListBean> {

    @Override
    protected void setToolBarTitle() {

    }

    @Override
    protected BaseRecyclerAdapter<PerformanceListBean> getRecyclerAdapter() {
        return new PerformerAdapter(this);
    }

    @Override
    protected Observable<ApiResultBean<ArrayList<PerformanceListBean>>> getObservable(boolean isRefresh) {
        return getApi().performanceLists(nextPageIndex, getPageSize());
    }


    private static class PerformerAdapter extends BaseRecyclerAdapter<PerformanceListBean> {
        public PerformerAdapter(Context context) {
            super(context, ONLY_FOOTER);
        }

        @Override
        protected RecyclerView.ViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
            return new PerformerHolder(mInflater.inflate(R.layout.item_performer, parent, false));
        }

        @Override
        protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, PerformanceListBean item, int position) {
            ((PerformerHolder) holder).tvItem.setText(item.toString());
        }
    }

    private static class PerformerHolder extends RecyclerView.ViewHolder {
        public final TextView tvItem;

        public PerformerHolder(View v) {
            super(v);
            tvItem = (TextView) v.findViewById(R.id.tv_item);
        }
    }

    @Override
    protected int getPageSize() {
        return 5;
    }
}
